package com.example.demo.connerlt;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.example.demo.DemoApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Arrays;

import static org.apache.logging.log4j.message.MapMessage.MapFormat.JSON;

@Component
@EnableScheduling
public class AlarmTask{

    public static void main(String[] args){
        String s[] ={"a","b","c"};
        JSONArray jsonArray=new JSONArray(Arrays.asList(s));
        System.out.println(jsonArray.toString());
    }
    /**
     * 定义执行线程启动的开关
     * @throws InterruptedException
     */
    @Scheduled(cron = "0/5 * * * * *")
    public void run() throws InterruptedException{
        Thread.sleep(6000);
        System.out.println(Thread.currentThread().getName() + " ==>使用时间" +System.currentTimeMillis()/1000);
    }

    /**
     * 对上一次执行时间之后再执行的时间
     * @throws InterruptedException
     */
    @Scheduled(fixedRate = 5000)
    public void run1() throws InterruptedException{
        Thread.sleep(7000);
        System.out.println(Thread.currentThread().getName() + " ==>使用时间" +System.currentTimeMillis()/1000);
    }
}
